home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / arm / gui / generalPanel.py < prev    next >
Encoding:
Python Source  |  2012-05-18  |  3.9 KB  |  125 lines

  1. """
  2. General panel.
  3. """
  4.  
  5. import random
  6. import sys
  7. import time
  8.  
  9. from collections import deque
  10.  
  11. import gobject
  12. import gtk
  13.  
  14. from cli.headerPanel import (HeaderPanel as CliHeaderPanel, VERSION_STATUS_COLORS)
  15. from util import connections, gtkTools, sysTools, torTools, uiTools
  16. from TorCtl import TorCtl
  17.  
  18. class GeneralPanel(CliHeaderPanel):
  19.   def __init__(self, builder):
  20.     CliHeaderPanel.__init__(self, None, time.time())
  21.  
  22.     self.builder = builder
  23.     self.filled = False
  24.     self._isTorConnected = torTools.getConn().isAlive()
  25.  
  26.     gobject.idle_add(self._fill_entries)
  27.     gobject.timeout_add(3000, self._timeout_fill_entries)
  28.  
  29.   def pack_widgets(self):
  30.     return
  31.  
  32.   def _timeout_fill_entries(self):
  33.     self._fill_entries()
  34.  
  35.     return True
  36.  
  37.   def _fill_entries(self):
  38.     self.valsLock.acquire()
  39.  
  40.     listStore = self.builder.get_object('liststore_general')
  41.     theme = gtkTools.Theme()
  42.  
  43.     listStore.clear()
  44.  
  45.     key = "arm"
  46.     value = "%s (%s %s)" % (self.vals['sys/hostname'], self.vals['sys/os'], self.vals['sys/version'])
  47.     row = (key, value, theme.colors['active'])
  48.     listStore.append(row)
  49.  
  50.     versionColor = VERSION_STATUS_COLORS[self.vals["tor/versionStatus"]] if \
  51.         self.vals["tor/versionStatus"] in VERSION_STATUS_COLORS else "black"
  52.     key = "Tor"
  53.     value = "%s (<span foreground=\"%s\">%s</span>)" % (self.vals['tor/version'], versionColor, self.vals['tor/versionStatus'])
  54.     row = (key, value, theme.colors['active'])
  55.     listStore.append(row)
  56.  
  57.     includeControlPort = True
  58.     key = "Relaying"
  59.     if self.vals["tor/orPort"]:
  60.       myAddress = "Unknown"
  61.       if self.vals["tor/orListenAddr"]: myAddress = self.vals["tor/orListenAddr"]
  62.       elif self.vals["tor/address"]: myAddress = self.vals["tor/address"]
  63.  
  64.       dirPortLabel = ", Dir Port: %s" % self.vals["tor/dirPort"] if self.vals["tor/dirPort"] != "0" else ""
  65.  
  66.       value = "%s%s%s%s" % (self.vals["tor/nickname"], " - " + myAddress, ":" + self.vals["tor/orPort"], dirPortLabel)
  67.     else:
  68.       if self._isTorConnected:
  69.         value = "Disabled"
  70.       else:
  71.         statusTime = torTools.getConn().getStatus()[1]
  72.  
  73.         if statusTime:
  74.           statusTimeLabel = time.strftime("%H:%M %m/%d/%Y, ", time.localtime(statusTime))
  75.         else: statusTimeLabel = ""
  76.  
  77.         value = "%s%s" % ("Tor Disconnected", statusTimeLabel)
  78.         includeControlPort = False
  79.     row = (key, value, theme.colors['active'])
  80.     listStore.append(row)
  81.  
  82.     key = "Control Port"
  83.     if includeControlPort:
  84.       if self.vals["tor/isAuthPassword"]: authType = "password"
  85.       elif self.vals["tor/isAuthCookie"]: authType = "cookie"
  86.       else: authType = "open"
  87.  
  88.       authColor = "red" if authType == "open" else "green"
  89.       value = "%s (<span foreground=\"%s\">%s</span>)" % (self.vals['tor/controlPort'], authColor, authType)
  90.     row = (key, value, theme.colors['active'])
  91.     listStore.append(row)
  92.  
  93.     if self.vals["stat/rss"] != "0": memoryLabel = uiTools.getSizeLabel(int(self.vals["stat/rss"]))
  94.     else: memoryLabel = "0"
  95.  
  96.     uptimeLabel = "N/A"
  97.     if self.vals["tor/startTime"]:
  98.       if self.isPaused() or not self._isTorConnected:
  99.         uptimeLabel = uiTools.getShortTimeLabel(self.getPauseTime() - self.vals["tor/startTime"])
  100.       else:
  101.         uptimeLabel = uiTools.getShortTimeLabel(time.time() - self.vals["tor/startTime"])
  102.  
  103.     key = "CPU"
  104.     value = "%s%% Tor, %s%% arm" % (self.vals["stat/%torCpu"], self.vals["stat/%armCpu"])
  105.     row = (key, value, theme.colors['active'])
  106.     listStore.append(row)
  107.  
  108.     key = "Memory"
  109.     value = "%s (%s%%)" % (memoryLabel, self.vals["stat/%mem"])
  110.     row = (key, value, theme.colors['active'])
  111.     listStore.append(row)
  112.  
  113.     key = "PID"
  114.     value = "%s" % (self.vals["tor/pid"] if self._isTorConnected else "")
  115.     row = (key, value, theme.colors['active'])
  116.     listStore.append(row)
  117.  
  118.     key = "Uptime"
  119.     value = uptimeLabel
  120.     row = (key, value, theme.colors['active'])
  121.     listStore.append(row)
  122.  
  123.     self.valsLock.release()
  124.  
  125.